@include('admin._include.header')

<body>

<div class="layui-fluid">
    <div class="larry-container">
        <div class="layui-row layui-col-space15 larryms-data-top">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                <script type="text/html" id="tools">
                    <button type="button" class="layui-btn" lay-event="add">添加规格</button>
                </script>
                <table lay-filter="ad_table" class="layui-table" lay-data="{height:'full-155',cellMinWidth:95,url:'{{url('sku/list')}}', page:true, id:'ad_table',toolbar:'#tools',defaultToolbar:[]}">
                    <thead>
                    <tr>
                        <th lay-data="{field:'sku_name',align:'center'}">规格名称</th>
                        <th lay-data="{field:'sku_value',align:'center'}">规格属性</th>
                        <th lay-data="{field:'create_at',align:'center'}">创建时间</th>
                        <th lay-data="{title:'操作',templet:'#listBar'}">操作</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>


<script type="text/html" id="listBar">
    <a class="layui-btn layui-btn-xs"  data-url="{{url('sku/edit')}}?id=@{{ d.id }}" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger"  data-url="{{url('sku/delete')}}?id=@{{ d.id }}" lay-event="delete">删除</a>
</script>

<script>
    layui.config({
        base: "/plugin/layuiadmin/"  //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function(){
        var $ = layui.$,
            form = layui.form,
            table = layui.table;


        table.on('toolbar(ad_table)', function(obj){
            var that = this;
            if (obj.event == 'add') {
                var index = layer.open({
                    title: "添加规格",
                    type: 2,
                    area: ['760px', '550px'],
                    scrollbar:true,
                    content: "{{url('sku/edit')}}",
                    end:function () {
                        $(that).removeAttr("data-flag");
                        layui.cache.layerIndex = null;
                        table.reload('ad_table')
                    }
                });
                // layer.full(index);
            }
        });

        table.on('tool(ad_table)', function(obj){
            var data = obj.data;
            var that = this;
            var url = $(this).data('url');

            switch (obj.event) {

                case 'edit':
                    layer.open({
                        title: data.sku_name,
                        type: 2,
                        area: ['760px', '550px'],
                        content: url,
                        end: function() {
                            $(that).removeAttr("data-flag");
                            layui.cache.layerIndex = null;
                            table.reload('ad_table')
                        }
                    });
                    break;

                case 'delete':
                    layer.confirm('是否确认删除', {
                        btn: ['取消','确认'], //按钮
                        title:'温馨提示'
                    }, function(){
                        layer.closeAll();
                    }, function(){
                        $.ajax({
                            url:url,
                            dateType:'json',
                            type:'post',
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            success:function (res) {
                                layer.closeAll();
                                layer.msg(res.message);
                                table.reload('ad_table')
                            }
                        });

                    });
                    break;

                default:
                    break;

            }

        });

    });

</script>
</body>

@include('admin._include.footer')


